<template>
	<view class="admin">
		<view class="uni-padding-wrap uni-common-mt admin-nav">
			<uni-segmented-control :current="current" :values="items" style-type="button" active-color="#007aff"
				@clickItem="onClickItem" />
		</view>
		<view class="list">
			<view v-if="current === 0">
				<uni-collapse accordion v-model="accordionValUser">
					<uni-collapse-item :title="(`${item.name || '患者'}`)" v-for="(item,index) of userManagement">
						<view class="content">
							<view>姓名：{{item.name|| '--'}}</view>
							<view>年龄：{{item.age|| '--'}}</view>
							<view>性别：{{item.sex == 0 ? '男':'女'}}</view>
							<view>手机号：{{item.mobilePhone|| '--'}}</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
			<view v-if="current === 1">
				<uni-collapse accordion v-model="accordionValDoctor">
					<uni-collapse-item :title="item.name" v-for="(item,index) of myPatient">
						<view class="content">
							<view>姓名：{{item.name|| '--'}}</view>
							<view>年龄：{{item.age|| '--'}}</view>
							<view>性别：{{item.sex == 0 ? '男':'女'}}</view>
							<view>手机号：{{item.mobilePhone|| '--'}}</view>
							<view>病情：{{item.registrationData[0].disease}}</view>
						</view>
						<view class="btn">
							<view class="edit" @click="success(item)">看诊</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
		</view>


		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="请对该病例进行评价" placeholder="请输入内容"
				@confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['所有病人', '我的病人'],
				current: 0,
				currentUser: this.$store.state.currentUser,
				accordionValUser: '',
				accordionValDoctor: '',

				userManagement: [],
				myPatient: [],
				evaluate: '',
				currentPatient: {}
			}
		},

		created() {

			this.userManagement = this.$store.state.userManagement.map(item => {
				console.log(item);
				if (item.registrationData != undefined && item.registrationData[0]
					.doctor == this
					.currentUser.account && item.registrationData[0].isConduct ==
					true) {
					this.myPatient.push(item)
				}
				// if (item.registrationData != undefined) {
				// 	let num = item.registrationData.length - 1
				// 	if (item.registrationData[num].doctor == this.currentUser
				// 		.account && item.registrationData[num].isConduct == true) {
				// 		console.log(123);
				// 	}
				// 	console.log(item.registrationData[num].doctor);
				// 	console.log(this.currentUser.account);
				// }
				if (item.name) {
					return item
				}
			})

			// console.log(this.myPatient);
			// console.log(this.currentUser);
			// console.log(this.$store.state.userManagement);


			this.userManagement = this.$store.state.userManagement
			this.doctorManagement = this.$store.state.doctorManagement
		},

		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
			success(data) {
				this.currentPatient = data
				this.currentPatient.registrationData[0].nowPosition = 2
				this.$refs.inputDialog.open()
				// console.log(this.myPatient.indexOf(this.currentPatient));
				// this.$store.commit('getLogin', this.currentUser)
				console.log(this.userManagement);
			},
			dialogInputConfirm(val) {
				this.currentPatient.registrationData[0].evaluate = val

				this.currentPatient.registrationData[0].isConduct = false
				this.myPatient.splice(this.myPatient.indexOf(this.currentPatient), 1)
				this.userManagement = this.userManagement.map(item => {
					if (item.account == this.currentPatient.account) {
						item = this.currentPatient
					}
					return item
				})
				this.$store.commit('setUserData', this.userManagement)

			}
		}
	}
</script>

<style lang="scss">
	.admin {
		width: 100vw;
		opacity: 0.8;
		background: linear-gradient(white, transparent);

		.admin-nav {
			width: 650rpx;
			margin: 0 auto
		}

		.list {
			margin-top: 20rpx;

			.content {
				padding: 0 25rpx;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				view {
					width: 300rpx;
					margin: 10rpx 0 20rpx 20rpx;
				}
			}

			.btn {
				height: 80rpx;
				display: flex;
				justify-content: center;

				view {
					width: 100rpx;
					height: 50rpx;
					line-height: 50rpx;
					text-align: center;
					background-color: red;
					margin-right: 20rpx;
					color: white;
				}

				.edit {
					background-color: skyblue;
				}
			}
		}
	}
</style>
